package com.ssextjs.data;

import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.List;

public class SqlProxy extends DataProxy{
	public String query;
	private Store store;
	
	public SqlProxy(Store st,String sql) {
		store=st;
		query = sql;
		System.err.println("SqlProxy loading. SQL: "+sql);
	}
	
	public Connection load(Connection con) {
		System.err.println("Execute SQL: "+query);
		try {
			Statement st = con.createStatement();
			ResultSet rs = st.executeQuery(query);
			List recs = ((SqlReader)store.reader).read(rs);
			store.setRecords(recs);
			store.rs_temp=rs;
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return con;
	}
}
